package thread;

public class ThreadDemo08 {
    static class MyRunnable implements Runnable{
        @Override
        public void run() {
            //两者均可
            //while(!Thread.interrupted()){
            while(!Thread.currentThread().isInterrupted()){
                System.out.println(Thread.currentThread().getName() + "：别管我，我忙着转账！");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    //注意此处要break
                    break;
                }
            }
            System.out.println(Thread.currentThread().getName() + "：啊！险些误了大事");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        MyRunnable runnable = new MyRunnable();
        Thread thread = new Thread(runnable, "李四");
        System.out.println(Thread.currentThread().getName() + "：让李四开始转账！");
        thread.start();
        Thread.sleep(10 * 1000);
        System.out.println(Thread.currentThread().getName() + "：老板来电话了，赶紧通知李四对方是骗子！");
        thread.interrupt();
    }
}
